namespace Smarts.Internal.Test.Core
{
    using System;
    using NUnit.Framework;
    using Smarts.Core;

    [TestFixture]
    public class RangeTests
    {
        [Test]
        public void EmptyRangeIsIdentified()
        {
            var range = Range.Create(5, 5);
            Assert.That(range.IsEmpty, Is.True);
            var date = DateTime.Today;
            Assert.That(Range.Create(date, date).IsEmpty, Is.True);
        }

        [Test]
        public void ContainsWorksAsExpected()
        {
            var range = Range.Create(10, 15);
            for (var i = 10; i <= 15; i++)
            {
                Assert.That(range.Contains(i), Is.True, "Range {0} should contain {1}.", range, i);
            }

            for (var i = 0; i < 10; i++)
            {
                Assert.That(range.Contains(i), Is.False, "Range {0} should not contain {1}.", range, i);
            }

            for (var i = 16; i < 20; i++)
            {
                Assert.That(range.Contains(i), Is.False, "Range {0} should not contain {1}.", range, i);
            }
        }

        [Test]
        public void IntersectsWorksAsExpected()
        {
            var rangeA = Range.Create(5, 10);
            var rangeB = Range.Create(10, 15);
            var rangeC = Range.Create(9, 11);
            Assert.That(rangeA.Intersects(rangeB), Is.False, "The range {0} does not intersect {1}", rangeA, rangeB);
            Assert.That(rangeB.Intersects(rangeA), Is.False, "The range {0} does not intersect {1}", rangeB, rangeA);
            Assert.That(rangeA.Intersects(rangeC), "The range {0} intersects {1}", rangeA, rangeC);
            Assert.That(rangeB.Intersects(rangeC), "The range {0} intersects {1}", rangeB, rangeC);
            Assert.That(rangeC.Intersects(rangeA), "The range {0} intersects {1}", rangeC, rangeA);
            Assert.That(rangeC.Intersects(rangeB), "The range {0} intersects {1}", rangeC, rangeB);
            Assert.That(rangeA.Intersects(rangeA), "The range {0} intersects {1}", rangeA, rangeA);
            Assert.That(rangeB.Intersects(rangeB), "The range {0} intersects {1}", rangeB, rangeB);
            Assert.That(rangeC.Intersects(rangeC), "The range {0} intersects {1}", rangeC, rangeC);
        }

        [Test]
        public void ContainsRangeWorksAsExpected()
        {
            var rangeA = Range.Create(1, 10);
            var rangeB = Range.Create(5, 10);
            var rangeC = Range.Create(5, 15);
            Assert.That(rangeA.Contains(rangeB));
            Assert.That(rangeC.Contains(rangeC));
            Assert.That(rangeA.Contains(rangeC), Is.False);
            Assert.That(rangeB.Contains(rangeA), Is.False);
            Assert.That(rangeB.Contains(rangeC), Is.False);
            Assert.That(rangeA.Contains(rangeA));
            Assert.That(rangeB.Contains(rangeB));
            Assert.That(rangeC.Contains(rangeC));
        }
    }
}